<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新增餐厅</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/module_form.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_memberAdd.css">
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<script src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
<style>
.cuisine_span{
	width:100px;
	display:inline-block;
}
</style>
</head>

<body>
	<div class="page_header">
		<div class="tabbar">
			<ul class="tab clearfix" tabname="tab1">
				<li class="tabhover" show="tab1_0">基本信息</li>
				<li show="tab1_1">地址信息</li>
				<li show="tab1_2">优惠信息</li>
				<li show="tab1_3">详细信息</li>
				<li show="tab1_4">缩略图</li>
			</ul>
		</div>
	</div>
	<div class="page_wraper">
	<form method="post" id="restaurantAdd_form">
		<input type="hidden" id="solevar" name="solevar" value="{:create_id()}">
		<div id="tab1_0" fortab="tab1">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title" style="width:130px;"><label for="cardnum">餐厅中文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="title" type="text" id="title"  placeholder="请输入中文名称,10个字符以内" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="cardnum">餐厅英文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="entitle" type="text" id="entitle"  placeholder="请输入英文名称，4个单词以内" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">订餐电话：<em>*</em></label></td>
					<td class="ele_content">
						<input name="tel" type="text" id="tel"  placeholder="请输入订餐电话" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="realname">营业时间：<em>*</em></label></td>
					<td class="ele_content">
						<input name="starthours" type="text" id="starthours" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate"> -
						<input name="endhours" type="text" id="endhours" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">营业时间：<em>*</em></label></td>
					<td class="ele_content" colspan="3">
						<input name="starthours" type="text" id="starthours1" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate"> -
						<input name="endhours" type="text" id="endhours1" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate">
						如果只有一个时间段，这里可以留空不填
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">餐厅邮箱：</label></td>
					<td class="ele_content">
						<input name="email" type="text" id="email"  placeholder="请输入餐厅邮箱" class="form_ele_text width_200"></td>
					<td class="ele_title"><label for="sex">经营类型：</label></td>
					<td class="ele_content">
						<select class="width_200" name="type" id="type">
							<option value="">请选择</option>
							<option value="1">直营店</option>
							<option value="2">加盟店</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="iccard">提供发票</label></td>
					<td class="ele_content" colspan="3">
						<input name="is_tigong" type="radio" checked value="1"> 是
						<input name="is_tigong" type="radio"  value="2"> 否
					</td>
					<!-- <td class="ele_title"><label for="iccard">餐厅税点：</label></td>
					<td class="ele_content">
						<input name="point" type="text" id="point"  placeholder="如：17，意味着：17%" class="form_ele_text width_200">
					</td> -->
					
				</tr>
				<tr>
					<td class="ele_title"><label for="iccard">餐厅折扣：</label></td>
					<td class="ele_content">
						<input name="coupon" type="text" id="coupon" placeholder="如：95，意味着：95折" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="phone">是否停业：</label></td>
					<td class="ele_content">
						<input name="is_tingye" type="radio" checked value="0">否&nbsp;&nbsp;&nbsp;
						<input name="is_tingye" type="radio"  value="1">是
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="iccard">餐厅星级：</label></td>
					<td class="ele_content">
						<select class="width_200" name="level" id="level">
							<option>请选择</option>
							<for start="5" end="0.1" step="-0.1" name="k" comparison="gt">
								<option value="{$k}">{$k}</option>
							</for>
						</select>
					</td>
					<td class="ele_title"><label for="iccard">是否延时：</label></td>
					<td class="ele_content">
						<input type="radio" name="is_yanshi" class="is_yanshi" value="2" checked>否&nbsp;&nbsp;&nbsp;
						<input type="radio" name="is_yanshi" class="is_yanshi" value="1">是
						<input type="text"  name="yanshi" id="yanshi" placeholder="时间：分钟" class="form_ele_text width_100" 
							style="display:none">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="phone">餐厅类型：</label></td>
					<td class="ele_content" colspan="3">
						<volist name="cuisine" id="v">
							<span class="cuisine_span">
								<input name="cuisine[]" type="checkbox" id="cuisine" value="{$v.id}">{$v.title}
							</span>
						</volist>
						
					</td>
				</tr>
				<tr style="height:50px;">
					<td colspan="4"></td>
				</tr>
			</table>
		</div>
		<div id="tab1_1" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<fieldset>
					<tr>
						<td class="ele_title"><label for="address1">所属地区：</label></td>
						<td colspan="3" class="ele_content">
							<div id="areaBox"></div>
						</td>
					</tr>
					<tr>
						<td class="ele_title"><label for="d_input">餐厅地址：</label></td>
						<td colspan="3" class="ele_content">
							城市地址：<input type="text" class="form_ele_text  width_250" name="ssxadd" id="ssxadd" readonly>
								   <input type="hidden" class="form_ele_text  width_250" name="enssxadd" id="enssxadd" readonly>
						</td>
					</tr>
					<tr>
						<td class="ele_title"><label for="d_input">&nbsp;</label></td>
						<td class="ele_content" colspan="3">
							详细地址：<input name="detail" type="text" class="form_ele_text  width_300" id="address" placeholder="请输入中文详细地址">
						</td>
					</tr>
					<tr>
						<td class="ele_title"><label for="d_input">&nbsp;</label></td>
						<td class="ele_content" colspan="3">
							详细地址：<input name="endetail" type="text" class="form_ele_text  width_300" id="address" placeholder="请输入英文详细地址">
						</td>
					</tr>
					<tr>
						<td class="ele_title"><label for="d_input">标注信息点</label></td>
						<td class="ele_content" colspan="3">
							<input type="button" id="btn_lbs" data-toggle="modal" class="form_ele_submit" value="标注信息点" style="background-color:#39C">
							<input id="pointlat" name="latitude" value="" type="text" class="form_ele_text  width_150" >
							<input id="pointlng" name="longitude" value="" type="text" class="form_ele_text  width_150" >
						</td>
					</tr>
				</fieldset>
			</table>
		</div>
		<div id="tab1_2" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title width_150"><label for="remark">免费配送：</label></td>
					<td class="ele_content">
						<input type="radio" name="is_exempt" value="1" checked>开启&nbsp;&nbsp;&nbsp;
						<input type="radio" name="is_exempt" value="2">关闭
					</td>
				</tr>
				<tr id="exemptprice">
					<td class="ele_title width_150"><label for="remark">减免费用：</label></td>
					<td class="ele_content">
						<input type="text" name="exemptprice" class="form_ele_text  width_200">
					</td>
				</tr>
				<tr id="exempt">
					<td class="ele_title"><label for="realname">免配送费时间：</label></td>
					<td class="ele_content">
					
						<input type="checkbox" value="1" name="week[]" checked>星期一&nbsp;
						<input type="checkbox" value="2" name="week[]" checked>星期二&nbsp;
						<input type="checkbox" value="3" name="week[]" checked>星期三&nbsp;
						<input type="checkbox" value="4" name="week[]" checked>星期四&nbsp;
						<input type="checkbox" value="5" name="week[]" checked>星期五&nbsp;
						<input type="checkbox" value="6" name="week[]">星期六&nbsp;
						<input type="checkbox" value="7" name="week[]">星期七&nbsp;&nbsp;&nbsp;
						
						<input name="exemptbegin" type="text" id="starthours" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate"> -
						<input name="exemptend" type="text" id="endhours" class="form_ele_text width_95"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm'})" class="Wdate">
					</td>
				</tr>
				<!-- <tr>
					<td class="ele_title width_150"><label for="remark">优惠信息（中文）：</label></td>
					<td class="ele_content">
						<textarea name="offers" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">优惠信息（英文）：</label></td>
					<td class="ele_content">
						<textarea name="enoffers" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">发票信息（中文）：</label></td>
					<td class="ele_content">
						<textarea name="invoice" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">发票信息（英文）：</label></td>
					<td class="ele_content">
						<textarea name="eninvoice" cols="" rows="" id="remark"></textarea></td>
				</tr> -->
			</table>
		</div>
		<div id="tab1_3" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（中文）：</label></td>
					<td class="ele_content">
						<textarea name="content" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（英文）：</label></td>
					<td class="ele_content">
						<textarea name="encontent" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">公告（中文）：</label></td>
					<td class="ele_content">
						<textarea name="service" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">公告（英文）：</label></td>
					<td class="ele_content">
						<textarea name="enservice" cols="" rows="" id="remark"></textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">特别说明：</label></td>
					<td class="ele_content">
						<textarea name="information" cols="" rows="" id="information"></textarea></td>
				</tr>
				<tr>
					<td colspan="4" style="height:30px;"></td>
				</tr>
			</table>
		</div>
		<div id="tab1_4" fortab="tab1" style="padding-left:8px;display:none;" class="clearfix" >
				<table cellpadding="0" cellspacing="0" class="module_form interlaceColor">
					<tr>
						<td class="ele_title"><label for="title">logo图片（4:3）：</label></td>
						<td class="ele_content" colspan="3">
							<div class="thumb lgthumb">
								<img src="__PUBLIC__/Images/nothumb.jpg"/>
								<input type="hidden" value="" name="thumb_url[]" id="thumb_url">
								<input type="hidden" name="thumb_title[]" value="">
								<input type="hidden" name="thumb_sort[]" value="0">
							</div>
							<iframe id="upload_frame" class="upload_frame" src="rest.php?s=FIL/Index/onefile&filetype=File&dealFun=thumb" frameborder="0"></iframe>
						</td>
					</tr>
					<tr>
						<td class="ele_title"><label for="title">场景图片（4:3）：</label></td>
						<td class="ele_content" colspan="3">
							<div class="thumb cjthumb">
								<img src="__PUBLIC__/Images/nothumb.jpg"/>
								<input type="hidden" value="" name="cjthumb_url[]" id="cjthumb_url">
								<input type="hidden" name="cjthumb_title[]" value="">
								<input type="hidden" name="cjthumb_sort[]" value="0">
							</div>
							<iframe id="upload_frame" class="upload_frame" src="rest.php?s=FIL/Index/onefile&filetype=File&dealFun=cjthumb" frameborder="0"></iframe>
						</td>
					</tr>
				</table>
		</div>
</form>
	</div>
	<div class="page_footer pdtd10">
		<input type="button" name="submit" id="submit" value="提交数据"  class="form_ele_submit"/>
		<input type="reset" name="reset" id="reset" value="清空数据"  class="form_ele_reset"/>
	</div>
</body>
<script type="text/javascript">
	//弹出窗口全局变量
	var api = frameElement.api, W = api.opener;
	var dealSelectFile = [];
	$(function(){
		//上传缩略图（4:3）
		var UPLOAD_PATH = '{$UPLOAD_PATH}';
		window.dealSelectFile['thumb'] = function(data){
			$('#thumb_url').val(data.filekey);
			$('.lgthumb>img').attr('src',UPLOAD_PATH+data.filekey);
		}
		window.dealSelectFile['cjthumb'] = function(data){
			$('#cjthumb_url').val(data.filekey);
			$('.cjthumb>img').attr('src',UPLOAD_PATH+data.filekey);
		}
		
		//滑动门
		$('.tabbar li').click(function(){
			var tabname = $('.tabbar>ul').attr('tabname');
			$('.tabbar li').removeClass('tabhover');
			$(this).addClass('tabhover');
			
			$('div[fortab="'+tabname+'"]').hide();
			$('#'+$(this).attr('show')).show();
		});
		
		//开启关闭优惠
		$("input[name='is_exempt']").on('click',function(){
			if($(this).val()==1){
				$("#exempt").show();
				$("#exemptprice").show();
			}else{
				$("#exempt").hide();
				$("#exemptprice").hide();
			}
		});
		
		//判断是否延时，延时的话需要将延时文本框显示出来
		$('.is_yanshi').on('click',function(){
			var val = $(this).val();
			if(val==1){
				$('#yanshi').show();
			}else{
				$('#yanshi').hide();
			}
		});
		
		//表格隔行换色
		$('.module_form tr:odd').addClass('odd');
		$('.module_form tr:even').addClass('even');
		
		//表单操作
		//重置
		$('.form_ele_reset').on('click',function(){
			$('#memberAdd_form').get(0).reset();
		});
		
		//提交
		$('#submit').on('click',function(){
			
			var tipsObj  = windowApi.lhgdialog.tips('正在提交数据...',5,etIcon.loading);
			var postData = $('#restaurantAdd_form').serialize();
			
			//通过Ajax提交表单
			postData += '&province='+$('#area2').val();
			postData += '&city='+$('#area2').val();
			postData += '&district='+$('#area3').val();
			
			$.post("{:U('Outlet/add')}", postData ,function(data){
					windowApi.lhgdialog.tips('数据提交成功！',1,etIcon.success,function(){
						frameApi.close(); //关闭当前窗口
						if(data.status==1){
							var obj = windowApi.lhgdialog.list['Outlet_index'];
							obj.reload(obj);
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				}, "json");
		});
		
		$('#btn_lbs').on('click',function(){
			var address = $('#ssxadd').val();
			var href    = "{:U('Outlet/outletLbs')}&address="+address;
			var width   = '600px';
			var height  = '420px';
			var title   = '标注信息点';
			openDialog('Outlet_outletLbs',href,width,height,title);
		});
	});
	
	var linkage_json   = {$json|json_encode} ;
	var linkage_jsonen = {$jsonen|json_encode};
	$(function(){
		//初始值处理
		var did = '';
		if(did!=''){
			$('#areaBox').html(dealInitialarea(did,'',1));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			//给英文城市地址赋值
			$('select[name="area"]').each(function(index, element) {				
				var areaid = $(this).val();
				if(linkage_jsonen[areaid]){
					enhtml += linkage_jsonen[areaid][0];
				}
			});
			
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			$('#enssxadd').val(enhtml);
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
		
		//处理初始值
		function dealInitialarea(lid,result,level){
			if(lid){
				$.each(linkage_json , function(i, n){
					if(lid==i){
						result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
						return false;
					}
				});
			}
			return result;
		}
		
		//响应select改变事件
		function showLinkagearea(pid,level,nid){
			var html = ''; //最终输出的HTML
			var have = false; //是否有子词典
			html += '<select name="area" id="area'+level+'" level="'+level+'">';
			html += '<option value="0">请选择</option>';
			$.each(linkage_json , function(i, n){
				if(pid==n[1]){
					if(nid==i){
						html += '<option value="'+i+'" selected>'+n[0]+'</option>';
					}else{
						html += '<option value="'+i+'">'+n[0]+'</option>';
					}
					have = true;
				}
			});
			html += '</select>';
			html += '<input type="hidden" name="area'+level+'"/>';
			
			//没有子词典则此次输出为空
			if(!have){
				html = '';
			}
			
			return html;
		}
	});
</script>
</html>
